"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var rxjs_1 = require("rxjs");
var common_1 = require("@nestjs/common");
var fs_1 = require("fs");
var FsService = /** @class */ (function () {
    function FsService() {
    }
    /**
     * 异步地改变文件的权限
     * @param path
     * @param mode
     */
    FsService.prototype.chmod = function (path, mode) {
        return rxjs_1.Observable.create(function (obser) {
            fs_1.chmod(path, mode, function (err) {
                if (err) {
                    obser.error(err);
                }
                obser.next();
                obser.complete();
            });
        });
    };
    FsService.prototype.chown = function (path, uid, gid) {
        return rxjs_1.Observable.create(function (obser) {
            fs_1.chown(path, uid, gid, function (err) {
                if (err) {
                    obser.error(err);
                }
                obser.next();
                obser.complete();
            });
        });
    };
    FsService.prototype.close = function (fd) {
        return rxjs_1.Observable.create(function (obser) {
            fs_1.close(fd, function (err) {
                if (err) {
                    obser.error(err);
                }
                obser.next();
                obser.complete();
            });
        });
    };
    FsService.prototype.copyFile = function (src, dest) {
        return rxjs_1.Observable.create(function (obser) {
            fs_1.copyFile(src, dest, function (err) {
                if (err) {
                    obser.error(err);
                }
                obser.next();
                obser.complete();
            });
        });
    };
    FsService.prototype.exists = function (path) {
        return rxjs_1.Observable.create(function (obser) {
            fs_1.exists(path, function (exists) {
                obser.next(exists);
                obser.complete();
            });
        });
    };
    FsService.prototype.mkdir = function (path, mode) {
        return rxjs_1.Observable.create(function (obser) {
            fs_1.mkdir(path, mode, function (err) {
                if (err) {
                    obser.error(err);
                }
                obser.next();
                obser.complete();
            });
        });
    };
    FsService.prototype.open = function (path, flags, mode) {
        return rxjs_1.Observable.create(function (obser) {
            fs_1.open(path, flags, function (err, fd) {
                if (err) {
                    obser.error(err);
                }
                obser.next(fd);
                obser.complete();
            });
        });
    };
    FsService.prototype.read = function (fd, buffer, offset, length, position) {
        return rxjs_1.Observable.create(function (obser) {
            fs_1.read(fd, buffer, offset, length, position, function (err, bytesRead, buffer) {
                if (err) {
                    obser.error(err);
                }
                obser.next({
                    bytesRead: bytesRead,
                    buffer: buffer
                });
                obser.complete();
            });
        });
    };
    FsService.prototype.readdir = function (path, options) {
        return rxjs_1.Observable.create(function (obser) {
            fs_1.readdir(path, options, function (err, files) {
                if (err) {
                    obser.error(err);
                }
                obser.next(files);
                obser.complete();
            });
        });
    };
    FsService.prototype.readFile = function (path, options) {
        return rxjs_1.Observable.create(function (obser) {
            fs_1.readFile(path, options, function (err, data) {
                if (err) {
                    obser.error(err);
                }
                obser.next(data);
                obser.complete();
            });
        });
    };
    FsService.prototype.rename = function (oldPath, newPath) {
        return rxjs_1.Observable.create(function (obser) {
            fs_1.rename(oldPath, newPath, function (err) {
                if (err) {
                    obser.error(err);
                }
                obser.next();
                obser.complete();
            });
        });
    };
    FsService.prototype.fstat = function () { };
    FsService.prototype.access = function () { };
    FsService.prototype.appendFile = function () { };
    FsService.prototype.rmdir = function () { };
    FsService.prototype.stat = function () { };
    FsService.prototype.unlink = function () { };
    FsService.prototype.watch = function () { };
    FsService = __decorate([
        common_1.Injectable()
    ], FsService);
    return FsService;
}());
exports.FsService = FsService;
